package me.zhengjie.modules.management.rest.web;

import cn.hutool.extra.template.Template;
import cn.hutool.extra.template.TemplateConfig;
import cn.hutool.extra.template.TemplateEngine;
import cn.hutool.extra.template.TemplateUtil;
import lombok.RequiredArgsConstructor;
import me.zhengjie.domain.EmailConfig;
import me.zhengjie.domain.vo.EmailVo;
import me.zhengjie.service.EmailService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * @Author: xin.peng
 * @Date: 2020/11/20
 * @Description :
 */
@RestController
@RequestMapping("/web/sendEmail")
@RequiredArgsConstructor
public class SendEmailController {

    private final EmailService emailService;

    @GetMapping
    public void sendEmail(){
        EmailVo emailVo = new EmailVo();
        emailVo.setSubject("【ITC招聘平台】您有一份新的简历待查收");
        Map<String, Object> data = new HashMap<>(16);
        TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH));
        Template template = engine.getTemplate("email/receiveResume.ftl");
        emailVo.setContent(template.render(data));
        //List<String> emails = Arrays.asList(quartzJob.getEmail().split("[,，]"));
        List<String> emails = new ArrayList<String>();
        emails.add("xin.peng@justech.com");
        emailVo.setTos(emails);
        EmailConfig emailConfig = emailService.find();
        System.out.println(emailConfig.toString());
        emailService.send(emailVo,emailConfig);
    }

}
